package com.silvaborgesmauricio.mydbversioning.core;

import java.util.Iterator;

public class Unit implements Comparable<Unit> {


	//TODO: really necessary?
	String path;
	Integer revision;
	
	
	public void commit() throws Exception {
		if (ChangeSet.existsConflictChangeSet(this)){
			throw new Exception ("There is another changeset encapsulating that unit");
		}
		//TODO: execute commit stuff
		this.revision++;
		this.path = this.path;
	}
	
	public void update(){
		
	}
	
	public int compareTo(Unit o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		result = prime * result
				+ ((revision == null) ? 0 : revision.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Unit other = (Unit) obj;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		if (revision == null) {
			if (other.revision != null)
				return false;
		} else if (!revision.equals(other.revision))
			return false;
		return true;
	}
	
}
